import java.util.Arrays;

public class Solution2285 {
    public long maximumImportance(int n, int[][] roads) {
        int[] f=new int[n];
        for (int[] road : roads) {
            f[road[0]]++;
            f[road[1]]++;
        }
        Arrays.sort(f);
        long ans=0;
        for (int i=0;i<n;i++){
            ans=ans+(long)(i+1)*f[i];
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution2285().maximumImportance(5,new int[][]{{0,1},{1,2},{2,3},{0,2},{1,3},{2,4}}));
    }
}
